import 'dart:io';

import 'package:example/utils/common.dart';
import 'package:example/data/bean/upload_img.dart';
import 'package:example/data/service/oss_service.dart';
import 'package:example/utils/future_ext.dart';
import 'package:get/get.dart';

import '../bean/base_response.dart';


class OssRepository {
  final service = Get.find<OssService>();

  /// 上传文件到oss
  Future<BaseResponse<UploadImg?>> uploadOss({
    required List<File> files,
    bool ignoreError = false,
    bool isLoading = true,
  }) async {
    if (isLoading) showLoading();
    return service
        .uploadOss(files,2)
        .handlerException<UploadImg?>(ignoreError: ignoreError)
        .whenComplete(() {
      if (isLoading) hideLoading();
    });
  }
  /// 上传文件到oss
  Future<BaseResponse<ImgUrl?>> uploadAvatar({
    required File file,
    bool ignoreError = false,
    bool isLoading = true,
  }) async {
    if (isLoading) showLoading();
    return service
        .uploadAvatar(file,1)
        .handlerException<ImgUrl?>(ignoreError: ignoreError)
        .whenComplete(() {
      if (isLoading) hideLoading();
    });
  }

}
